<template>
  <div class="home">
    <b-container class="bv-example-row bv-example-row-flex-cols">
      <b-row align-v="center">
        <b-col>
          <b-card title="登录" class="text-center" sub-title="欢迎光临">
            <b-form-group horizontal breakpoint="lg" label="登录信息" label-size="lg" label-class="font-weight-bold pt-0" class="mb-0">
              <b-form-group horizontal label="Username:" label-class="text-sm-right" label-for="nestedStreet">
                <b-form-input id="nestedStreet" v-model="user.account"></b-form-input>
              </b-form-group>
              <b-form-group horizontal label="Password:" label-class="text-sm-right" label-for="nestedCity">
                <b-form-input id="nestedCity" v-model="user.psw"></b-form-input>
              </b-form-group>
            </b-form-group>
            <b-button @click="login">登录</b-button>
          </b-card>
        </b-col>
      </b-row>
    </b-container>
  </div>
</template>
<script>
export default {
  name: "home",
  data() {
    return {
      user: {
        account: "",
        psw: ""
      }
    };
  },
  methods: {
    login: async function() {
      let redirect = this.$auth.redirect();
      this.$auth.login({
        headers: {
          "Content-Type": "application/json"
        },
        data: this.user,
        rememberMe: true,
        redirect: {
          name: redirect ? redirect.from.name : "home"
        },
        success(res) {
          window.localStorage.setItem("auth-token", res.data.token);
        }
      });
    }
  }
};
</script>
